/*
 * 创建日期 2009-11-26
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.db.bean;

import  org.fantasy.common.util.StringUtil;

import java.math.BigDecimal;


/**
 *  查询结果中一行中的一列。
 * @author: 王文成
 * @version: 1.0
 * @since 2009-11-26
 */
public class ReportCell extends Cell{

    /**
     * isTop
     */
    private boolean isTop = true;
    
    /**
     * rowspan
     */
    private int rowspan = 1;
    
    /**
     * 横向：下一个元素
     */
    private ReportCell xNext;
    
    /**
     * 纵向：下一个元素
     */
    private ReportCell yNext;
    
    /**
     * 横向：上一个元素
     */
    private ReportCell xPrevious;
    
    /**
     * 纵向：上一个元素
     */
    private ReportCell yPrevious;
    
    /**
     * 父节点
     */
    private ReportCell topCell = this;
    
    public ReportCell(){
    }
    
    public boolean isTop() {
        return isTop;
    }

    public ReportCell getTopCell() {
        return topCell;
    }

    public void setTopCell(ReportCell topCell) {
        this.topCell = topCell;
    }

    public void setTop(boolean isTop) {
        this.isTop = isTop;
    }

    public int getRowspan() {
        return rowspan;
    }
    
    public BigDecimal getBigDecimal() {
        Class colClass = getColClass();
        if( colClass != null ){
            if( BigDecimal.class.isAssignableFrom(colClass) ){
                return (BigDecimal)getValue();
            }if( Number.class.isAssignableFrom(colClass) ){
                return new BigDecimal(((Number)getValue()).doubleValue());
            }
        }
        String value = (String)getString();
        return new BigDecimal( StringUtil.isValid(value) ? value.trim() : "0");
    }

    public void setRowspan(int rowspan) {
        this.rowspan = rowspan;
    }
    

    public void setXNext(ReportCell next) {
        xNext = next;
    }

    public void setXPrevious(ReportCell previous) {
        xPrevious = previous;
    }

    public void setYNext(ReportCell next) {
        yNext = next;
    }

    public void setYPrevious(ReportCell previous) {
        yPrevious = previous;
    }

    public ReportCell xNext(){
        return xNext;
    }

    public ReportCell yNext(){
        return yNext;
    }
    
    public ReportCell xPrevious(){
        return xPrevious;
    }
    
    public ReportCell yPrevious(){
        return yPrevious;
    }
    
    public void increaseRowspan(){
        rowspan = rowspan + 1;
    }
    
    /**
     * 表格值相加
     */
    public void add( ReportCell cell ){
        BigDecimal b = getBigDecimal();
        setColClass( BigDecimal.class );
        setValue(b.add( cell.getBigDecimal()));
    }
    
    public String getDesc(){
        StringBuffer b = new StringBuffer();
        b.append("{");
        b.append("isTop=" + isTop);
        b.append(";rowspan=" + getRowspan());
        b.append(";value=" + getValue());
        b.append("}");
        return b.toString();
    }
    
    public static void main(String[] args) {
        new BigDecimal(" 9");
    }
}
